package com.anolesoft.yr.mbus.code.mapper;

import com.anolesoft.yr.mbus.code.entity.CodeMaxSequenceDO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author zhj
 * @date 2020/9/27 10:26
 */
@Mapper
public interface CodeMaxSequenceMapper {
    /**
     *  插入
     * @param codeMaxSequence codemaxsequcece
     * @return int
     */
    @Insert("insert into code_maxsequence (" +
            "objuid, " +
            "code_main_uid, " +
            "sequence_name, " +
            "code_item_uid, " +
            "property_value, " +
            "max_sequence" +
            ") values (" +
            "#{objuid,jdbcType=VARCHAR}, " +
            "#{codeMainUid,jdbcType=VARCHAR}, " +
            "#{sequenceName,jdbcType=VARCHAR}, " +
            "#{codeItemUid,jdbcType=VARCHAR}, " +
            "#{propertyValue,jdbcType=VARCHAR}, " +
            "#{maxSequence,jdbcType=INTEGER}" +
            ")")
    int insert(CodeMaxSequenceDO codeMaxSequence);

    /**
     * 修改
     * @param codeMaxSequence codeMaxSequence
     * @return int
     */
    @Update("update code_maxsequence set " +
            "code_main_uid = #{codeMainUid,jdbcType=VARCHAR}, " +
            "sequence_name = #{sequenceName,jdbcType=VARCHAR}, " +
            "code_item_uid = #{codeItemUid,jdbcType=VARCHAR}, " +
            "property_value = #{propertyValue,jdbcType=VARCHAR}, " +
            "max_sequence = #{maxSequence,jdbcType=VARCHAR} " +
            "where objuid = #{objuid,jdbcType=VARCHAR}")
    int update(CodeMaxSequenceDO codeMaxSequence);


    /**
     * 查询
     * @param id id
     * @return CodeMaxSequence
     */
    @Results(id = "CodeMaxSequenceResultMap",value = {
            @Result(id = true, column = "objuid", property = "objuid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "code_main_uid", property = "codeMainUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sequence_name", property = "sequenceName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "code_item_uid", property = "codeItemUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "property_value", property = "propertyValue", jdbcType = JdbcType.VARCHAR),
            @Result(column = "max_sequence", property = "maxSequence", jdbcType = JdbcType.BIGINT)
    })
    @Select("select " +
            "objuid, " +
            "code_main_uid, " +
            "sequence_name, " +
            "code_item_uid, " +
            "property_value, " +
            "max_sequence " +
            "from code_maxsequence " +
            "where objuid = #{id,jdbcType=VARCHAR}")
    CodeMaxSequenceDO selectOneById(@Param("id") String id);

    /**
     * 查询
     * @param codeMainUid codeMainUid
     * @param sequenceName sequenceName
     * @return CodeMaxSequence
     */
    @Select("select " +
            "objuid, " +
            "code_main_uid, " +
            "sequence_name, " +
            "code_item_uid, " +
            "property_value, " +
            "max_sequence " +
            "from code_maxsequence " +
            "where sequence_name = #{sequenceName,jdbcType=VARCHAR} and code_main_uid = #{codeMainUid,jdbcType=VARCHAR}")
    CodeMaxSequenceDO selectOneByCodeMainUidAndSequenceName(@Param("codeMainUid") String codeMainUid, @Param("sequenceName") String sequenceName);


}

